package com.gxuwz.endrskyweather.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import com.gxuwz.endrskyweather.Weather24hFragment;
import com.gxuwz.endrskyweather.Weather7dFragment;
import com.gxuwz.endrskyweather.Weather15dFragment;

public class ForecastPagerAdapter extends FragmentStateAdapter {

    private String cityName;
    private String cityCode;

    public ForecastPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    public ForecastPagerAdapter(@NonNull Fragment fragment) {
        super(fragment);
    }

    public ForecastPagerAdapter(@NonNull Fragment fragment, String cityName, String cityCode) {
        super(fragment);
        this.cityName = cityName;
        this.cityCode = cityCode;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        switch (position) {
            case 0: return Weather24hFragment.newInstance(cityName, cityCode);
            case 1: return Weather7dFragment.newInstance(cityName, cityCode);
            case 2: return Weather15dFragment.newInstance(cityName, cityCode);
            default: return Weather24hFragment.newInstance(cityName, cityCode);
        }
    }

    @Override
    public int getItemCount() {
        return 3; // 24h, 7d, 15d
    }
}
